const Router = require('koa-router');
const {db, Op,QueryTypes } = require("../../models/db");
const tool = require("../../tools/tool");
const router = new Router();
// mt5信号
router.post('/app/mt5', async ctx => {
    let body= ctx.request.body
    let txt = body.txt
    let action = body.action
    if(action && action == "save") {
        let model = await db.models['mt5'].findOne({
            where: {op: 'mt'}
        })
        if(model) {
            model.txt = txt
            model.ut = tool.getTime()
            await model.save()
            return ctx.suc('修改成功')
        }
        else {
            model = db.models['mt5'].build()
            model.op = 'mt'
            model.txt = txt
            model.ut = tool.getTime()
            await model.save()
            return ctx.suc('保存成功')
        }
    }
    let model = await db.models['mt5'].findOne({
        where: {op: 'mt'}
    })
    return ctx.suc('suc', model)
})

module.exports = router;
